package com.starry.module.system.core.post.controller.admin;

import cn.hutool.http.HttpStatus;
import com.starry.core.common.domain.R;
import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.web.core.controller.BaseController;
import com.starry.core.web.core.logger.annotation.OperationLog;
import com.starry.core.web.core.logger.enums.OperateTypeEnum;
import com.starry.module.system.api.post.domain.qo.SysPostPageQo;
import com.starry.module.system.api.post.domain.qo.SysPostQo;
import com.starry.module.system.api.post.domain.vo.SysPostDtlVo;
import com.starry.module.system.api.post.domain.vo.SysPostVo;
import com.starry.module.system.core.post.service.SysPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 系统岗位
 *
 * @author xiaoke
 */
@Tag(name = "系统岗位")
@RestController
@RequestMapping("/system/sysPost")
public class SysPostController extends BaseController {

    private final SysPostService sysPostService;
    private final OAuth2AuthorizationService oAuth2AuthorizationService;

    public SysPostController(SysPostService sysPostService, OAuth2AuthorizationService oAuth2AuthorizationService) {
        this.sysPostService = sysPostService;
        this.oAuth2AuthorizationService = oAuth2AuthorizationService;
    }

    /**
     * 分页查询
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @OperationLog(operateType = OperateTypeEnum.GET, responseEnable = true)
    @Operation(summary = "系统岗位-分页查询")
    @GetMapping("sysPostPage")
    public R<PageVo<SysPostVo>> findPage(SysPostPageQo pageQo) {
        return success(this.sysPostService.page(pageQo));
    }

    /**
     * 查询列表
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "系统岗位-查询列表")
    @GetMapping("sysPostList")
    public R<List<SysPostVo>> findList(SysPostPageQo pageQo) {
        return success(this.sysPostService.findList(pageQo));
    }

    /**
     * 详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "系统岗位-详情")
    @GetMapping("sysPostDetails/{id}")
    public R<SysPostDtlVo> findById(@PathVariable("id") Long id) {
        return success(this.sysPostService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysPostQo 实体对象
     * @return 新增结果
     */
    @Operation(summary = "系统岗位-新增")
    @PostMapping("sysPostCreate")
    public R<Long> insert(@RequestBody @Validated SysPostQo sysPostQo) {
        return success(HttpStatus.HTTP_CREATED, this.sysPostService.save(sysPostQo));
    }

    /**
     * 修改数据
     *
     * @param sysPostQo 实体对象
     * @return 修改结果
     */
    @Operation(summary = "系统岗位-修改")
    @PostMapping("sysPostUpdate")
    public R<Void> update(@RequestBody @Validated SysPostQo sysPostQo) {
        this.sysPostService.updateById(sysPostQo);
        return success();
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统岗位-删除")
    @PostMapping("sysPostRemove")
    public R<Void> delete(@RequestParam("idList") Set<Long> idList) {
        this.sysPostService.removeByIds(idList);
        return success();
    }

    /**
     * 启用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统岗位-启用")
    @PostMapping("sysPostEnable")
    public R<Void> enable(@RequestParam("idList") Set<Long> idList) {
        this.sysPostService.enable(idList);
        return success();
    }

    /**
     * 禁用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统岗位-禁用")
    @PostMapping("sysPostDisable")
    public R<Void> disable(@RequestParam("idList") Set<Long> idList) {
        this.sysPostService.disable(idList);
        return success();
    }
}

